import request from "@/utils/request"


function getPageInfo(pageId, openid) {
  return request({
    url: '/h5/page/' + pageId,
    method: 'get',
    params: {
      openid: openid
    }
  })
}

function lockCouponCode(data) {
  return request({
    url: '/h5/page/coupon/code/lockCode',
    method: 'post',
    data: data
  })
}

function receiveCouponCode(data) {
  return request({
    url: '/h5/page/coupon/code/receiveCode',
    method: 'post',
    data: data
  })
}

function unlockCouponCode(data) {
  return request({
    url: '/h5/page/coupon/code/unlockCode',
    method: 'post',
    data: data
  })
}

function getUserCoupons(pageId, openid) {
  return request({
    url: `/h5/page/coupon/code/${pageId}/${openid}`,
    method: 'get'
  })
}

function play(pageId, openid) {
  return request({
    url: `/h5/page/play/${pageId}/${openid}`,
    method: 'post',
    data: {}
  })
}

function getStock(pageId, couponId) {
  let url = `/h5/page/coupon/getStock/${pageId}`
  if (couponId) {
    url = url + `/${couponId}`
  }
  return request({
    url: url,
    method: 'get'
  })
}

export default {
  getPageInfo,
  lockCouponCode,
  getUserCoupons,
  receiveCouponCode,
  unlockCouponCode,
  play,
  getStock
}
